package cz.muni.fi.pa165.bookingmanager.dto;

import cz.muni.fi.pa165.bookingmanager.other.PaymentStatusEnum;
import java.math.BigDecimal;
import java.sql.Date;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 *
 * @author Jiří Holuša
 */
public class ReservationDTO {

    private Long id;
    private List<CustomerDTO> customers = null; //customers that are using this reservation
    private Date startDate = null; //sice from the reservation is valid
    private int duration; //for how long the reservation is valid since startDate
    private BigDecimal totalPrice; //Room.price * duration
    private RoomDTO room; //reserved room
    private HotelDTO hotel;
    private PaymentStatusEnum paid;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public List<CustomerDTO> getCustomers() {
        if (customers == null) {
            return null;
        }

        return Collections.unmodifiableList(customers);
    }

    public void setCustomers(List<CustomerDTO> customers) {
        this.customers = null;

        if (customers != null) {
            this.customers = new ArrayList<CustomerDTO>();
            this.customers.addAll(customers);
        }
    }

    public int getDuration() {
        return duration;
    }

    public void setDuration(int duration) {
        this.duration = duration;
    }

    public HotelDTO getHotel() {
        return hotel;
    }

    public void setHotel(HotelDTO hotel) {
        this.hotel = hotel;
    }

    public PaymentStatusEnum isPaid() {
        return paid;
    }

    public void setPaid(PaymentStatusEnum paid) {
        this.paid = paid;
    }

    public RoomDTO getRoom() {
        return room;
    }

    public void setRoom(RoomDTO room) {
        this.room = room;
    }

    public Date getStartDate() {
        if (startDate == null) {
            return null;
        }

        return new Date(startDate.getTime());
    }

    public void setStartDate(Date startDate) {
        this.startDate = null;

        if (startDate == null) {
            return;
        }

        this.startDate = new Date(startDate.getTime());
    }

    public BigDecimal getTotalPrice() {
        return totalPrice;
    }

    public void setTotalPrice(BigDecimal totalPrice) {
        this.totalPrice = totalPrice;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        if (!(object instanceof ReservationDTO)) {
            return false;
        }

        ReservationDTO other = (ReservationDTO) object;
        if ((this.id == null) || (this.id != null && !this.id.equals(other.getId()))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "ReservationDTO{" + "id=" + id + ", customers=" + customers + ", startDate=" + startDate + ", duration=" + duration + ", totalPrice=" + totalPrice + ", room=" + room + ", hotel=" + hotel + ", paid=" + paid + '}';
    }
}
